#!/usr/bin/env python

import sys
from xml.dom import minidom

import gbase
import getpass
from xml_helper import *
import gbase_template
import if_gbase

try:
    from bot_conf import conf
except:
    print "Can't read the configure file: bot_conf.py"
    print "maybe you must copy bot_conf.py.default to bot_conf.py"
    sys.exit(1)

TEST_DATA = '''
the config file of logrotate
	/usr/src/test/aa 
{
	size 1k
	create
	rotate 10
	compress
	missingok
	postrotate
	/usr/bin/killall -HUP a.out
	endscript
}

the code write in C
#include
#include
#include
#include
#include
#include
#include
extern int errno;
int fd;
void hup_handler(int sig)
{
init_f();
}
init_f()
{
close(fd);
fd=open("aa",O_RDWR | O_CREAT | O_APPEND, S_IWRITE | S_IREAD);
}
int main()
{
signal(SIGHUP, hup_handler);
init_f();
while(1)
{
if(-1==write(fd,"asdfsda\n",8))
{
perror(NULL);
};
usleep(10);
}
}
'''

def main():
	if_gbase.init(conf)
	objid = if_gbase.StoreObj('persistence-title', TEST_DATA)
	print objid
	content = if_gbase.LoadObj(objid)
	print content
	if objid:
		if_gbase.DelObj(objid)
    
if __name__ == '__main__':
    main()
